﻿function UploadCard(id, id1, id2) {
    $.ajaxFileUpload({
        url: 'UploadFile?path=' + $('#name').val() + $('#mobile').val(), //用于文件上传的服务器端请求地址
        secureuri: false, //是否需要安全协议，一般设置为false
        fileElementId: id, //文件上传域的ID
        dataType: 'text/html', //返回值类型 一般设置为json
        success: function (data, status) {
            if (data!='0') {
                $("#" + id1).val(data);
                var element = document.getElementById(id2);
                element.src = "../../Resourse/" + data;
            } else {
                $.notify({
                    message: '<i class="fa fa-exclamation"></i> 请上传文件',
                    status: "danger",
                    pos: "bottom-right"
                });
            }
        }, error: function (data, status, e) {
            alert(e);
        }
    });
    return false;
}
function UploadHead(id) {
    $("#" + id).click();
}
$(function () {
    $('#btnSpecialPolicySave').click(function () {
        AjaxSave();
    });
});
function GetValues() {
    var obj = {};
    obj.name = $('#name').val();
    obj.sex = $('#sex').val();
    obj.mobile = $('#mobile').val();
    obj.cardno = $('#cardno').val();
    obj.bloodType = $('#bloodType').val();
    obj.illnesshistory = $('#illnesshistory').val();
    obj.emergencycontact = $('#emergencycontact').val();
    obj.emergencycontactmobile = $('#emergencycontactmobile').val();
    obj.policynumber = $('#policynumber').val();
    obj.company = $('#company').val();
    obj.insureanceAgent = $('#insureanceAgent').val();
    obj.numberplate = $('#numberplate').val();
    obj.VIN = $('#drivingnumber').val();
    obj.driving = $('#enginenumber').val();
    obj.card = $('#card').val();
    obj.password = $('#password').val();
    obj.cardpic = $('#headerfile').val();
    obj.option1 = $('#handfile').val();
    return obj;
}
function ShowInfo(msg) {
    $.notify({
        message: '<i class="fa fa-exclamation"></i> ' + msg,
        status: "danger",
        pos: "bottom-right"
    });
}

function AjaxSave() {
    var obj = GetValues();
    if ($('#name').val() == '') {
        ShowInfo("会员名称必填"); return;
    }
    if ($('#sex').val() == '') {
        ShowInfo("性别必选"); return;
    }
    if ($('#mobile').val() == '') {
        ShowInfo("会员电话必填"); return;
    }
    //if ($('#cardno').val() == '') {
    //    ShowInfo("身份证号必填"); return;
    //}

    var cd = /^[A-Za-z0-9]{18}/;// /(\d{18}) || (\d{17}[A-Z]{1})/;//定义身份证匹配算法
    var legalIdCard = $("#cardno").val();//获取前台界面字段值
    if (legalIdCard != null && legalIdCard != "") {//运用匹配方法直接判断
        if (cd.test(legalIdCard) == false) {
            alert("输入身份证号不合法!");
            $("#cardno").val("");//将前台输入值置为空
            return false;
        }
    }
    else if ($('#cardno').val() == '') {
        ShowInfo("身份证号必填"); return;
    }

    if ($('#emergencycontact').val() == '') {
        ShowInfo("紧急联系人必填"); return;
    }
    if ($('#emergencycontactmobile').val() == '') {
        ShowInfo("紧急联系人电话必填"); return;
    }
    if ($('#policynumber').val() == '') {
        ShowInfo("保单号必填"); return;
    }
    if ($('#company').val() == '') {
        ShowInfo("保险公司必填"); return;
    }
    if ($('#numberplate').val() == '') {
        ShowInfo("车牌必填"); return;
    }
    if ($('#drivingnumber').val() == '') {
        ShowInfo("车架号必填"); return;
    }
    if ($('#enginenumber').val() == '') {
        ShowInfo("发动机号必填");
        return;
    } if ($('#card').val() == '') {
        ShowInfo("卡号必填");
        return;
    } if ($('#password').val() == '') {
        ShowInfo("密码必填");
        return;
    }
    $.ajax({
        url: 'ActivityZHXJ',
        data: { "json": JSON.stringify(obj) },
        method: 'POST',
        success: function (result) {
            result = eval('(' + result + ')');
            alert(result.Message);
            if (result.IsSucceed) {
                window.location.reload();
            }
        }
    });
}